<template>
  <el-select v-model="value" placeholder="请选择" style="width: 320px;" @change="handleChange">
    <el-option-group v-for="group in options" :key="group.label" :label="group.label">
      <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
      </el-option>
    </el-option-group>
  </el-select>
</template>

<script>
import { getAllUserInfo } from '../../api/capitalChannel';
export default {
  name: 'ChannelAdmin',
  props: [],
  data() {
    return {
      options: [
      ],
      value: ''
    }
  },
  created() {
    getAllUserInfo().then(res => {
      console.log(res)
      this.options.push({
        label: '系统管理员',
        options: []
      });
      this.options.push({
        label: '普通管理员',
        options: []
      });
      let usersList = res.data;
      if (usersList instanceof Array) {
        usersList.forEach(item => {
          if (item.userId == 1 || item.userId == 2) {
            this.options[0].options.push({
              value: item.userId,
              label: item.nickName
            });
          } else {
            this.options[1].options.push({
              value: item.userId,
              label: item.nickName
            });
          }
        })
      }
    }).catch();
  },
  methods: {
    handleChange(val){
      this.$emit('selectedAdminChange',val)
    }
  }
}
</script>